﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using BathhouseService.Models.SqlModels;


namespace BathhouseService.CURD.ViewModels.ServiceRecordVMs
{
    public partial class ServiceRecordListVM : BasePagedListVM<ServiceRecord_View, ServiceRecordSearcher>
    {
        protected override List<GridAction> InitGridAction()
        {
            return new List<GridAction>
            {
                this.MakeStandardAction("ServiceRecord", GridActionStandardTypesEnum.Create, "新建","CURD", dialogWidth: 800),
                this.MakeStandardAction("ServiceRecord", GridActionStandardTypesEnum.Edit, "修改","CURD", dialogWidth: 800),
                this.MakeStandardAction("ServiceRecord", GridActionStandardTypesEnum.Delete, "删除", "CURD",dialogWidth: 800),
                this.MakeStandardAction("ServiceRecord", GridActionStandardTypesEnum.Details, "详细","CURD", dialogWidth: 800),
                this.MakeStandardAction("ServiceRecord", GridActionStandardTypesEnum.BatchEdit, "批量修改","CURD", dialogWidth: 800),
                this.MakeStandardAction("ServiceRecord", GridActionStandardTypesEnum.BatchDelete, "批量删除","CURD", dialogWidth: 800),
                this.MakeStandardAction("ServiceRecord", GridActionStandardTypesEnum.Import, "导入","CURD", dialogWidth: 800),
                this.MakeStandardAction("ServiceRecord", GridActionStandardTypesEnum.ExportExcel, "导出","CURD"),
            };
        }

        protected override IEnumerable<IGridColumn<ServiceRecord_View>> InitGridHeader()
        {
            return new List<GridColumn<ServiceRecord_View>>{
                this.MakeGridHeader(x => x.OrderId),
                this.MakeGridHeader(x => x.Names_view),
                this.MakeGridHeader(x => x.ServicePersonName),
                this.MakeGridHeader(x => x.CustomerName),
                this.MakeGridHeader(x => x.PaymentTime),
                this.MakeGridHeader(x => x.Score),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<ServiceRecord_View> GetSearchQuery()
        {
            var query = DC.Set<ServiceRecord>()
                .CheckContain(Searcher.OrderId, x=>x.OrderId)
                .CheckEqual(Searcher.ValueAddedServicesId, x=>x.ValueAddedServicesId)
                .CheckContain(Searcher.ServicePersonName, x=>x.ServicePersonName)
                .CheckContain(Searcher.CustomerName, x=>x.CustomerName)
                .CheckBetween(Searcher.PaymentTime?.GetStartTime(), Searcher.PaymentTime?.GetEndTime(), x => x.PaymentTime, includeMax: false)
                .Select(x => new ServiceRecord_View
                {
				    ID = x.ID,
                    OrderId = x.OrderId,
                    Names_view = x.ValueAddedServices.Names,
                    ServicePersonName = x.ServicePersonName,
                    CustomerName = x.CustomerName,
                    PaymentTime = x.PaymentTime,
                    Score = x.Score,
                })
                .OrderByDescending(x => x.ID);
            return query;
        }

    }

    public class ServiceRecord_View : ServiceRecord{
        [Display(Name = "服务名称")]
        public String Names_view { get; set; }

    }
}
